const heimatoken=localStorage.getItem("heimatoken")
if (!heimatoken) {
    location.href='login.html'
}
const logout=document.querySelector('.logout')
const topMenuList=document.querySelectorAll('.nav>li>a')//拿一级标题的
const secondMenuList=document.querySelectorAll('.nav ul a')//拿二级标题
const initBtm=document.querySelector('.init')
logout.addEventListener('click',function(e){
   
       if (confirm('是否退出')) {
            localStorage.removeItem("heimatoken")
            location.href='login.html'
            
       }
        
    

})
// console.log(topMenuList)
// console.log(secondMenuList)


topMenuList.forEach(topA => {
    topA.addEventListener('click',function(e){
        // 用原生来写
        // topA.nextElementSibling.classList.toggle("show")

        // jquery来写$(dqs).slideToggle(写变化时间)
        $(topA.nextElementSibling).slideToggle(300)
    })
});
secondMenuList.forEach(secondA => {
    secondA.addEventListener('click',function(e){
        document.querySelector('.nav ul a.active').classList.remove("active")
        this.classList.add("active")
        

    })
});
// 没有实际数据，从后端提供的接口拿到假的数据
initBtm.addEventListener('click',async function(e){
    const result=await axios({
        url:"/init/data",
        method:'get',
        // 将请求头加入
  /*       headers:{
            Authorization:heimatoken,//如果接口没说一般按项目经验来说请求头token参数属性名Authorization
        } */
    })
    console.log(result)
    
    if (result.data.code===0) {
        toastr.success(result.data.message)
    }

})